<template>
   <div class="box">
    <van-image
        width="60vw"
        fit="cover"
        position="center"
         :src="require('../../assets/img/logo2.png')"
      />
    <van-cell-group inset>

      <van-field class="tt"
        v-model="userInfo.phone"
        name="手机号"
        label="手机号"
        placeholder="手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"
      />
      <van-field class="tt"
        v-model="userInfo.password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field class="tt"
        v-model="userInfo.password2"
        name="确认密码"
        label="确认密码"
        placeholder="确认密码"
        :rules="[{ required: true, message: '请确认密码' }]"
      />

      <div class="denglu" @click="denglu">已有账号，去登陆</div>
    </van-cell-group>
     <div style="margin: 16px;width:80vw">
        <van-button
          round
          block
          native-type="submit"
          color="#FF6A4D"
          @click="addUser"
        >
          提交
        </van-button>
      </div>
  </div>

</template>

<script>
import { Notify } from "vant";
import { regestUser } from "../../request/api.js";
export default {
  data() {
    return {
      userInfo: {
        phone: "",
        nickname: "",
        password: "",
        password2: "",
      },
    };
  },
  methods: {
    denglu(){
      this.$router.push('/login')
    },
    addUser() {
      regestUser(this.userInfo)
        .then((d) => {
          if (d.data.code == 200) {
            Notify({ type: "success", message: d.data.msg });
            this.$router.push("/login");
          } else {
            Notify({ background:"#FF6A4D", message: d.data.msg });
          }
          console.log(d);
        })
        .catch((e) => {
          console.log(e);
        });
    },
  },
};
</script>

<style scoped>
.box{
      display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    
}
.tt{
  margin-top: 10px;
}
.denglu{
  font-size: 13px;
  text-align: right;
  color: #ff6041;
}
</style>